﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using cmsservice.Entity;
using cmsservice.DAL;

/// <summary>
///NewStockTPBLL 的摘要说明
/// </summary>
public class NewStockTPBLL
{
    public string GetList(int top)
    {
        string key = "typeId:" + "A0305" + "_" + top.ToString();
        string str = (string)MemcachedTools.Get(key);

        NewsDAL dal=new NewsDAL ();
        List<NewEntity> list = dal.GetNewStockTP(top);

        var newList = new List<entity.NewsList>();
        foreach (var li in list)
        {
            var tmp = new entity.NewsList();
            tmp.Id = li.id;
            tmp.Title = li.title;
            tmp.Step = li.step;
            tmp.Url = li.OutsideUrl;
            tmp.PTime = li.ptime;
            tmp.Source = li.Source;
            tmp.ImageUrl = li.ImageUrl;
            tmp.Nature = li.Nature;
            tmp.KeyWord = li.keyword;
            newList.Add(tmp);
        }

        //输出对象
        var zData = new NewsList_Lst { typename = "个股分析", typeid = "A0305", list = newList };

        str = Newtonsoft.Json.JsonConvert.SerializeObject(zData);
        MemcachedTools.Add(key, str, DateTime.Now.AddHours(1));
        return str;

    }
    /// <summary>
    /// 点睛输出
    /// </summary>
    /// <returns></returns>
    public string GetnewDMSList(string code)
    {
        newDMSListDAL dal = new newDMSListDAL();
        List<NewsList> list = dal.getDMSListDAL(code);
        string key = "typeId:" + code;
        string str = (string)MemcachedTools.Get(key);

        var newList = new List<entity.NewsList>();
        foreach (var li in list)
        {
            var tmp = new entity.NewsList();
            tmp.Id = li.Id;
            tmp.Title = li.Title;
            tmp.PTime = li.PTime;
            newList.Add(tmp);
        }

        //输出对象
        var zData = new NewsList_Lst { typename = "益盟点睛", typeid = code, list = newList };
        str = Newtonsoft.Json.JsonConvert.SerializeObject(zData);
        MemcachedTools.Add(key, str, DateTime.Now.AddHours(1));
        return str;
    }
    public string GetOne(int newId)
    {
        try
        {
            NewsDAL dal = new NewsDAL();
            NewEntity en = dal.GetNewStockTPOne(newId);

            string key = "news22:" + newId.ToString();
            string str = (string)MemcachedTools.Get(key);
            if (!string.IsNullOrEmpty(str))
            {
                return str;
            }
            NewsEntity c = null;

            c = new NewsEntity();
            var temp = en;
            c.Author = temp.author;
            c.Content = temp.content;
            c.Id = temp.id;
            c.KeyWord = temp.keyword;
            c.PTime = temp.ptime;
            c.Source = temp.Source;
            c.Stcok = temp.Stock;
            c.Title = temp.title;
            c.Summary = temp.Summary;
            c.ImageUrl = temp.ImageUrl;
            c.Url = temp.OutsideUrl;

            str = JsonBLL.ToJson(c);
            MemcachedTools.Add(key, str, DateTime.Now.AddHours(24));
            return str;
        }
        catch
        {
            return null;
        }
    }
    public string GetDMSOne(int newId)
    {
        try
        {
            NewsDAL dal = new NewsDAL();
            NewEntity en = dal.getDMSListDALONE(newId);

            string key = "news22:" + newId.ToString();
            string str = (string)MemcachedTools.Get(key);
            if (!string.IsNullOrEmpty(str))
            {
                return str;
            }
            NewsEntity c = null;

            c = new NewsEntity();
            var temp = en;
            c.Author = temp.author;
            c.Content = temp.content;
            c.Id = temp.id;
            c.KeyWord = temp.keyword;
            c.PTime = temp.ptime;
            c.Source = temp.Source;
            c.Stcok = temp.Stock;
            c.Title = temp.title;
            c.Summary = temp.Summary;
            c.ImageUrl = temp.ImageUrl;
            c.Url = temp.OutsideUrl;

            str = JsonBLL.ToJson(c);
            MemcachedTools.Add(key, str, DateTime.Now.AddHours(24));
            return str;
        }
        catch
        {
            return null;
        }
    }
    public string GetOneByStock(string secuCode)
    {
        return "";
    }

}